package com.linwen.excise.leetcode;

/**
 * @ClassName _1534统计好三元组
 * @Description TODO
 * @Author zero
 * @DATE 2024/9/22 1:35 AM
 * @Version 1.0
 */
public class _1534统计好三元组 {
    public static void main(String[] args) {
        _1534统计好三元组 inst = new _1534统计好三元组();
        System.out.println(inst.countGoodTriplets(new int[]{3,0,1,1,9,7},7,2,3));
    }
    public int countGoodTriplets(int[] arr, int a, int b, int c) {
        int result = 0;
        for (int i = 0; i < arr.length; i++) {
            for (int j = i + 1; j < arr.length; j++) {
                if (Math.abs(arr[i] - arr[j]) > a) {
                    continue;
                }
                for (int k = j + 1; k < arr.length; k++) {
                    if (Math.abs(arr[j] - arr[k]) <= b && Math.abs(arr[i] - arr[k]) <= c) {
                        result++;
                    }
                }
            }
        }
        return result;
    }
}
